package net.bithappens.hnqe.query;

import java.util.ArrayList;
import java.util.List;

import net.bithappens.hnqe.IllegalParamException;

public class ConstraintMath extends Constraint {

	
	public enum MathOperation {
		ADD,
		SUB,
		MUL,
		DIV;
	}

	public enum MathCompare {
		EQUAL,
		GREATHER,
		GREATHEREQUAL,
		LESS,
		LESSEQUAL,
	}
	
	public class CalcStep{
		CalcStep(MathOperation operation, Atom operant) throws IllegalParamException{
			if(operation == null){
				throw new IllegalParamException("The operation is not allowed to be NULL");
			}
			if(operant == null){
				throw new IllegalParamException("The operant is not allowed to be NULL");
			}
			this.operation = operation;
			this.operant = operant;
		}
		private MathOperation operation;
		private Atom operant;
		
		public MathOperation getOperation() {
			return operation;
		}
		public Atom getOperant() {
			return operant;
		}
		
		@Override
		public String toString() {
			return "[CalcStep| operation=" + operation + ", operant=" + operant + "]";
		}
		
	}


	private List<CalcStep> mathTerms = new ArrayList<CalcStep>();
	
	private MathCompare compare;
	
	public ConstraintMath(Atom result, MathCompare compare) throws Exception {
		if(result == null){
			throw new IllegalParamException("The result is not allowed to be NULL");
		}
		if(compare == null){
			throw new IllegalParamException("The compare operation is not allowed to be NULL");
		}
		
		this.constrainee = result;
		this.compare = compare;
	}
	
	
	
	public void addCalcStep(MathOperation operation, Atom operant) throws IllegalParamException{
		mathTerms.add(new CalcStep(operation, operant));
	}
	
	
	public List<CalcStep> getMathTerms(){
		return mathTerms;
	}
	
	public MathCompare getComparator(){
		return compare;
	}
	
	@Override
	public Atom[] getParams() {
		Atom[] params = new Atom[mathTerms.size()];
		int i = 0;
		for(CalcStep step : mathTerms){
			params[i++] = step.operant;
		}
		return params;
	}



	@Override
	public String toString() {
		return "[ConstraintMath| mathTerms=" + mathTerms + ", compare=" + compare + "]";
	}

	
	
	
}
